package com.example.core.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.example.core.entity.PageDataInfo;
import com.example.core.result.Res;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class BaseController {
    public Res<Void> toR(int rows) {
        return rows > 0 ? Res.ok() : Res.fail();
    }

    public Res<Void> toR(boolean result) {
        return result ? Res.ok() : Res.fail();
    }

    public <T> PageDataInfo<T> getPageDataInfo(List<T> list) {
        if (CollectionUtil.isEmpty(list)) {
            return PageDataInfo.empty();
        }
        return PageDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}